<!-- components/custom-tab-bar/custom-tab-bar.vue -->
<template>
  <view class="custom-tab-bar">
    <view 
      class="tab-item" 
      :class="{ active: current === 0 }"
      @click="switchTab(0)"
    >
      <uni-icons type="home" size="24"></uni-icons>
      <text>首页</text>
    </view>
    <view 
      class="tab-item" 
      :class="{ active: current === 1 }"
      @click="switchTab(1)"
    >
      <uni-icons type="chat" size="24"></uni-icons>
      <text>消息</text>
      <uni-badge v-if="messageCount > 0" :text="messageCount" type="error" absolute="rightTop"></uni-badge>
    </view>
    <view 
      class="tab-item" 
      :class="{ active: current === 2 }"
      @click="switchTab(2)"
    >
      <uni-icons type="person" size="24"></uni-icons>
      <text>我的</text>
    </view>
  </view>
</template>

<script>
export default {
  name: "CustomTabBar",
  props: {
    current: {
      type: Number,
      default: 0
    },
    messageCount: {
      type: Number,
      default: 0
    }
  },
  methods: {
    switchTab(index) {
      const pages = ['/pages/guanliyuan/index', '/pages/guanliyuan/message', '/pages/guanliyuan/my']
      uni.switchTab({
        url: pages[index]
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.custom-tab-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 50px;
  display: flex;
  align-items: center;
  justify-content: space-around;
  background-color: #ffffff;
  box-shadow: 0 -1px 5px rgba(0, 0, 0, 0.1);
  z-index: 999;
  
  .tab-item {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    color: #666;
    
    &.active {
      color: #007AFF;
    }
    
    uni-icons {
      margin-bottom: 2px;
    }
  }
}
</style>